<?php

/**
 * LISTER
 *
 * Params:
 * 		
 *   
 */
class zdUserListerComponents extends sfComponents
{
	
	public function setSort(&$c, $order, $field) {
		if ($order == 'asc')
			$c->addAscendingOrderByColumn ( $field );
		else
			$c->addDescendingOrderByColumn ( $field );
	}
	
  public function executeListUser($request)
  {
  	

			
  	
  	 if(isset($this->seo_title))
  	 {
  	 	$seo = $this->seo_title;
  	 }
  	 else {
  	 	$seo = 'Заголовок не задан';
  	 }
  	   ////Устанавливаем заголовки
		  	$this->getResponse()->addMeta('description', $seo);
		    $this->getResponse()->addMeta('keywords', $seo);
		    $this->getResponse()->addMeta('title', $seo);
	   ////   
  	 
		 
  	
        $c = new Criteria();
        $c->add(sfGuardUserPeer::IS_ACTIVE,true);  
        $c->add(sfGuardUserPeer::IS_OTPUSK,false);
        $c->add(sfGuardUserPeer::IS_PARTNER,false);
        $c->add(sfGuardUserPeer::IS_SUPER_ADMIN,false);
          
        
     
        //// Поиск 
        
         if(isset($this->keyword))
        { 
        	$crit1=$c->getNewCriterion(sfGuardUserPeer::NICKNAME,'%'.$this->keyword.'%',Criteria::LIKE);
			$crit2=$c->getNewCriterion(sfGuardUserPeer::USERNAME,'%'.$this->keyword.'%',Criteria::LIKE);
			$crit1->addOr($crit2);       
			$c->add($crit1);	        
        }
        
        ////тор
           if(isset($this->top))
        {       
			$c->add(sfGuardUserPeer::IS_TOP,true);	        
        }    
        
        ////новые
           if(isset($this->new))
        {       
			$c->addDescendingOrderByColumn(sfGuardUserPeer::ID);
        }  
        

      
        
        
    	
    // pager
    
        //// Сортировка
        if(isset($this->sort_rating))
        {
        		$c->addDescendingOrderByColumn(sfGuardUserPeer::RATING);
        		
        }
         elseif(isset($this->sort_date))
        {
        		$c->addDescendingOrderByColumn(sfGuardUserPeer::ID);
        }
        elseif(sfConfig::get('app_use_vip_in_top')==true)
        {
        		$c->addDescendingOrderByColumn(sfGuardUserPeer::IS_VIP);
        }
           elseif(isset($this->sort_last_login))
        {
        		$c->addDescendingOrderByColumn(sfGuardUserPeer::LAST_LOGIN);
        }
        else 
        {
        	    $orders = array ('asc' => 'desc', 'desc' => 'asc' );
		if (! isset ( $this->sort ))
			$this->sort = $this->getRequestParameter ( 'sort', 4 );
		
		if (! isset ( $this->order ))
			$this->order = $this->getRequestParameter ( 'order', 'desc' );
			
  		switch ($this->sort) {
			case 1 :
				$this->setSort ( $c, $this->order, sfGuardUserPeer::RATING );
				break; // рейтинг
			case 2 :
				$this->setSort ( $c, $this->order, sfGuardUserPeer::ID );
				break; // оценка
			case 3 :
				$this->setSort ( $c, $this->order, sfGuardUserPeer::LAST_LOGIN );
				break;
			

		     }	
        }
    
        ///
        

        
         
        
        ///Фильтр по полу
          if(isset($this->gender))
        {
        		$c->addAnd(sfGuardUserPeer::GENDER,$this->gender);
        		
        }
        ///
        
    	$this->per_page = $this->getVar('per_page', 10);
        if (!isset($this->page))
        	$this->page = $this->getRequestParameter('page', 1);

      
        
        $pager = new sfPropelPager('sfGuardUser', $this->per_page);
        $pager->setCriteria($c);
        $pager->setPeerMethod('doSelect');        
        $pager->setPage($this->page);
        $pager->init();
        $this->pager = $pager;
  }


  
}
?>